<?php

namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Session;
use think\Config;
use think\Request;
use think\Hook;
use ding\auth\Authons;
use ding\Operation;
use think\Response;

class Common extends Controller
{
    /*
     * 数据表前缀
     */
    protected $prefix = '';
    protected $_module = '';
    protected $_controller = '';
    protected $_action = '';
    protected $sid = 0;     //用户ID
    protected $role = 0;
    
    public function _initialize() {
        parent::_initialize();
        $this->_check_login();
        $this->prefix = Config::get('database.prefix');
        $this->_init_input();
    }
    
    protected function _check_login() {
        if (!Session::has('userinfo')) {
            $response = ding_json(98, 'Not login');
            $response->send($response);
        }
    }

    protected function _init_input() {
        $request = Request::instance();
        $this->_module = $request->module();
        $this->_controller = $request->controller();
        $this->_action = $request->action();
        //$this->_test_set_login();
        $this->sid = Session::get('userinfo.sid');
        $this->role = Session::get('userinfo.role');
    }
    
    /*
     * 空操作
     */
    public function _empty() {
        abort(404,'页面不存在啊，别乱入啊！');
    }
}
